﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Backend
{

    [KnownType(typeof(Flight))]
    [KnownType(typeof(Passenger))]
    [DataContract]
   public class Ticket
    {
        [DataMember]
        Flight flight;

        [DataMember]
        List<Passenger> passengers;

        [DataMember]
        private double totalPrice;

        [DataMember]
        private String ticketReff;


        public Ticket(Backend.Flight flight, List<Passenger> passengers)
        {
            
            this.flight = flight;
            this.passengers = passengers;
            totalPrice = flight.TotalPrice;
            GenerateTicketReference();
        }

   


        private  void GenerateTicketReference()
        {
            string def = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            Random rnd = new Random();
            StringBuilder ret = new StringBuilder();
            for (int i = 0; i < 6; i++)
                ret.Append(def.Substring(rnd.Next(def.Length), 1));
           
            ticketReff= ret.ToString();
        }

        public double TotalPrice
        {
            get { return totalPrice; }
            set { totalPrice = value; }
        }

        public String TicketReff
        {
            get { return ticketReff; }
            set { ticketReff = value; }
        }

        public Flight Flight
        {
            get { return flight; }
            set { flight = value; }
        }

        public List<Passenger> Passengers
        {
            get { return passengers; }
            set { passengers = value; }
        }

   

      
      
    }

}
